import axios from "axios"
/**用户登录**/
async function UserLogin2( loginformDTO){
  var result
  await axios({
      baseURL: 'api/user/login',
      data: loginformDTO,
      
      headers: {'Content-Type': 'application/json;charset=UTF-8' },
      method: 'post',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


/**用户注册**/
async function UserRegistr2(tbUser){
  var result
  await axios({
      baseURL: 'api/user/register',
      data: tbUser,
      
      headers: {'Content-Type': 'application/json;charset=UTF-8' },
      method: 'post',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}

/**me**/
async function Me(){
  var result
  await axios({
      baseURL: 'api/user/me',
      method: 'get',

  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}

/**getUserById**/
async function Info(userId){
  var result
  await axios({
      baseURL: 'api/user/info/'+userId,
      method: 'get',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}



/**myallinfo**/
async function MyAllInfo(){
  var result
  await axios({
      baseURL: 'api/user/myallinfo',
      method: 'get',
      // headers:{
      //   'authorization':window.localStorage['token']
      // }
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


async function Update(tbUser){
  var result
  await axios({
      baseURL: 'api/user/update',
      data: tbUser,
      method: 'put',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


async function UpdatePWS(passwordDTO){
  var result
  await axios({
      baseURL: 'api/user/updatepws',
      data: passwordDTO,
      method: 'put',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}



async function OutLogin2(){
  var result
  var token = localStorage.getItem("token")
  await axios({
      baseURL: 'api/user/outlogin',
      data: token,
      method: 'delete',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}



export default {
  name: 'UserAPI',
  UserLogin2,
  UserRegistr2,
  Me,
  Info,
  MyAllInfo,
  Update,
  UpdatePWS,
  OutLogin2

}




